// shopPages/quanbupingj/quanbupingj.js
import {
  get_carte,
  update_coll_status,
  update_like_status,
  update_flag_like_status,
  baseUrl,
  ftp_share_image,
  radar_add,
  get_open_id,
  user_login,
  update_scan,
  update_user_invite
} from "../../utils/api.js";
var page = 1;
var newsList = [];
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    more_status:false,
    
  },
  // 全屏展示图片
  showPicture: function (e) {
    // console.log(e)
    let img_src = e.currentTarget.dataset.src
    wx.previewImage({
      current: img_src, // 当前显示图片的http链接
      urls: [img_src] // 需要预览的图片http链接列表
    })
  },
  getMoreComment:function(goods_id){
    var that = this;
    var more_status = that.data.more_status;
    var url2 = '/shop/goodsComment';
    var params2 = {
      goods_id: goods_id,
      pageno: page
    };

    wx.showLoading({
      title: '数据加载中',
    })
    app.HttpPostSend(url2, params2, function (res) {
      wx.hideLoading();
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        var commentList = res.data.comment;
        for (let i = 0; i < commentList.length; i++) {
          newsList.push(commentList[i]);
        }

        if (commentList.length < 4) {
          more_status = false;
        } else {
          more_status = true;
          page += 1;

        }
        that.setData({
          comment: newsList,
          more_status: more_status,

        })

      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    var goodsId = options.goods_id;
    var that = this;
    that.setData({
      goodsId: options.goods_id
    });
    newsList = [];
    page=1;
    that.getMoreComment(options.goods_id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    console.log(that.data.more_status);
    if (that.data.more_status == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      that.getMoreComment(that.data.goodsId);

    } else {
      wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})